# -*- coding: utf-8 -*-
"""
Created on Thu Jan 15 10:00:33 2021

@author: Jing
"""
from Crawler.save_data import save_data
import pandas as pd


# 加载数据，存入库
def load_dd(data):
    table_name = 'prod_netvalues'
    data = data.fillna(0)
    zero_num = len(data[data['netvalue'].apply(lambda x: x == 0)])
    if zero_num <= 5:
        for x in range(len(data)):
            dat = {
                'date': int(data['date'][x]),
                'prodname': data['prodname'][x],
                'netvalue': data['netvalue'][x]
            }
            d = save_data(dat, table_name)
    else:
        print('缺少数据过多，拒绝插入')


if __name__=='__main__':
    data = pd.read_excel('C:/Users/wzer/Desktop/data_set/中信0104合并.xlsx', header=0)
    s = load_dd(data)